package dao

import (
	"fmt"
	__ "user-srv/basic/proto"
	"user-srv/handler/models"
	"user-srv/pkg"
)

// 用户意见反馈
func UserOpinionAdd(in *__.UserOpinionAddReq) (*models.UserOpinion, error) {
	var userOpinion models.UserOpinion

	userOpinion.UserId = in.UserId           //用户id
	userOpinion.Name = in.Name               //称呼
	userOpinion.Mobile = in.Mobile           //联系方式
	userOpinion.OpinionType = in.OpinionType //意见类型

	userOpinion.OpinionTitle = in.OpinionTitle //意见标题

	if pkg.Baid(in.OpinionDetails) == false {
		return nil, fmt.Errorf("意见标题包含不适当内容，请修改")
	}

	userOpinion.OpinionDetails = in.OpinionDetails //意见详情

	err := userOpinion.UserOpinionAdd()
	if err != nil {
		return nil, fmt.Errorf("用户意见反馈添加失败:%v", err)
	}

	return &userOpinion, nil
}
